package com.example.demo.common.validator;

import cn.hutool.core.util.IdcardUtil;
import com.example.demo.common.validator.annotation.IdCard;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author zhaiding
 * @since 2019-09-06
 */
public class IdCardValidator implements ConstraintValidator<IdCard, String> {

    @Override
    public void initialize(IdCard constraintAnnotation) {
    }

    /**
     * @param value   注解字段的值
     * @param context context in which the constraint is evaluated
     * @return 通过返回 true
     */
    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        return IdcardUtil.isValidCard(value);
    }
}
